using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;


[UxmlElement("MenuElement")]
public partial class MenuElement : VisualElement
{
    // [UxmlAttribute] public string btnStatsName;
    //
    // [UxmlAttribute, UxmlTypeReference(typeof(VisualElement))]
    // public Type  btnStats { get; set; }
    //
    // [SerializeField]
    // public VisualTreeAsset m_Uxml;

    // [UxmlAttribute, UxmlTypeReference(typeof(Button))]
    [SerializeField] public Button btnStats { get; set; }
    public Label stats { get; set; }

    [Header("stats active color")]
    [UxmlAttribute]
    Color _styleColor;
    StyleColor _defstyleColor;

    public MenuElement()
    {
        // 延迟绑定确保元素加载完成
        RegisterCallback<AttachToPanelEvent>(evt =>
        {
            btnStats = this.Q<Button>("btnStats");
            stats = this.Q<Label>("stats");
            _defstyleColor = btnStats.style.backgroundColor;
            //  Debug.Log(btnStats);
            if (btnStats != null)
            {
                btnStats.RegisterCallback<ClickEvent>(OnClick);
            }

            ShowStats(false);
        });
    }

    private void OnClick(ClickEvent evt)
    {
        if(stats==null)return;
        ShowStats(stats.style.display != DisplayStyle.Flex);
    }

    void ShowStats(bool isShow)
    {
        if(stats==null)return;
        if (isShow)
        {
            btnStats.style.backgroundColor = new StyleColor(_styleColor);
            stats.style.display = DisplayStyle.Flex;
        }
        else
        {
            btnStats.style.backgroundColor = _defstyleColor;
            stats.style.display = DisplayStyle.None;
        }
    }
}